//utf-8
		
	var idOfFolderTrees = ['ajax_tree'];
	
	var imageFolder = '../../lovejes/tree/ajaxtree/images/';	// Path to images
	var folderImage = 'dhtmlgoodies_folder.gif';
	var isFoldopen = false;//支持文件夹打开和关闭功能,如果要美观的话，更改folderImage
	
	var folderOpenImage = 'folderOpen.gif';
	var plusImage = 'dhtmlgoodies_plus.gif';
	var minusImage = 'dhtmlgoodies_minus.gif';
	var initExpandedNodes = '';	// Cookie - initially expanded nodes;
	var useAjaxToLoadNodesDynamically = true;
	var ajaxRequestFile = 'writeNodes.php';
	var contextMenuActive = true;	// Set to false if you don't want to be able to delete and add new nodes dynamically
	
	var ajaxObjectArray = new Array();
	var treeUlCounter = 0;
	var nodeId = 1;
	
	/*
	These cookie functions are downloaded from 
	http://www.mach5.com/support/analyzer/manual/html/General/CookiesJavaScript.htm
	*/
	function Get_Cookie(name) { 
	   var start = document.cookie.indexOf(name+"="); 
	   var len = start+name.length+1; 
	   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
	   if (start == -1) return null; 
	   var end = document.cookie.indexOf(";",len); 
	   if (end == -1) end = document.cookie.length; 
	   return unescape(document.cookie.substring(len,end)); 
	} 
	// This function has been slightly modified
	function Set_Cookie(name,value,expires,path,domain,secure) { 
		expires = expires * 60*60*24*1000;
		var today = new Date();
		var expires_date = new Date( today.getTime() + (expires) );
	    var cookieString = name + "=" +escape(value) + 
	       ( (expires) ? ";expires=" + expires_date.toGMTString() : "") + 
	       ( (path) ? ";path=" + path : "") + 
	       ( (domain) ? ";domain=" + domain : "") + 
	       ( (secure) ? ";secure" : ""); 
	    document.cookie = cookieString; 
	} 
	
	function expandAll(treeId)
	{
		var menuItems = document.getElementById(treeId).getElementsByTagName('LI');
		for(var no=0;no<menuItems.length;no++){
			var subItems = menuItems[no].getElementsByTagName('UL');
			if(subItems.length>0 && subItems[0].style.display!='block'){
				showHideNode(false,menuItems[no].id.replace(/[^0-9]/g,''));
			}			
		}
	}
	
	function collapseAll(treeId)
	{
		var menuItems = document.getElementById(treeId).getElementsByTagName('LI');
		for(var no=0;no<menuItems.length;no++){
			var subItems = menuItems[no].getElementsByTagName('UL');
			if(subItems.length>0 && subItems[0].style.display=='block'){
				showHideNode(false,menuItems[no].id.replace(/[^0-9]/g,''));
			}			
		}		
	}
	
	function getNodeDataFromServer(ajaxIndex,ulId,parentId){
		document.getElementById(ulId).innerHTML = ajaxObjectArray[ajaxIndex].response;
		ajaxObjectArray[ajaxIndex] = false;
		parseSubItems(ulId,parentId);
	}

	
	function parseSubItems(ulId,parentId){
		/**
		if(initExpandedNodes){
			var nodes = initExpandedNodes.split(',');
		}
		*/
		var branchObj = document.getElementById(ulId);
		//all sub node
		var menuItems = branchObj.getElementsByTagName('LI');
		for(var no=0;no<menuItems.length;no++){
			var imgs = menuItems[no].getElementsByTagName('IMG');
			//已经树型就不解析
			if(imgs.length>0)continue;
			nodeId++;
			var subItems = menuItems[no].getElementsByTagName('UL');
			
			var img = document.createElement('IMG');
			img.src = imageFolder + plusImage;
			img.onclick = showHideNode;
			//是否有下一级
			if(subItems.length==0){
				img.style.visibility='hidden';
			}else{
				subItems[0].id = 'tree_ul_' + treeUlCounter;
				treeUlCounter++;
			}
			
			var aTag = menuItems[no].getElementsByTagName('A')[0];
			//aTag.onclick = showHideNode;
			aTag.ondblclick = showHideNode;
			if(contextMenuActive)aTag.oncontextmenu = showContextMenu;
			
			menuItems[no].insertBefore(img,aTag);
			//insert folder
			menuItems[no].id = 'dhtmlgoodies_treeNode' + nodeId;
			var folderImg = document.createElement('IMG');
			if(menuItems[no].className){
				folderImg.src = imageFolder + menuItems[no].className;
			}else{
				folderImg.src = imageFolder + folderImage;
			}
			menuItems[no].insertBefore(folderImg,aTag);
			
			/**
			if(subItems.length!=0){
				var tmpParentId = menuItems[no].getAttribute('parentId');
				alert(tmpParentId);
				if(!tmpParentId)tmpParentId = menuItems[no].tmpParentId;
				if(tmpParentId && nodes[tmpParentId])showHideNode(false,nodes[no]);	
			}
			*/
			
		}		
	}
		
	
	function showHideNode(e,inputId){
		//plus + img
		if(inputId){
			if(!document.getElementById('dhtmlgoodies_treeNode'+inputId))return;
			thisNode = document.getElementById('dhtmlgoodies_treeNode'+inputId).getElementsByTagName('IMG')[0]; 
		}else {
			thisNode = this;
			if(this.tagName=='A'){
				thisNode = this.parentNode.getElementsByTagName('IMG')[0];
			}
			
		}
		if(thisNode.style.visibility=='hidden')return;
		var parentNode = thisNode.parentNode;
		var foldImg = parentNode.getElementsByTagName('IMG')[1];
		inputId = parentNode.id.replace(/[^0-9]/g,'');
		if(thisNode.src.indexOf(plusImage)>=0){//展开
			thisNode.src = thisNode.src.replace(plusImage,minusImage);
			if(isFoldopen){//文件夹展开,hyh
				foldImg.src = foldImg.src.replace(folderImage,folderOpenImage);
			}

			var ul = parentNode.getElementsByTagName('UL')[0];
			ul.style.display='block';
			
			if(!initExpandedNodes)initExpandedNodes = ',';
			if(initExpandedNodes.indexOf(',' + inputId + ',')<0) initExpandedNodes = initExpandedNodes + inputId + ',';
			
			if(useAjaxToLoadNodesDynamically){	// Using AJAX/XMLHTTP to get data from the server
				var firstLi = ul.getElementsByTagName('LI')[0];
				
				if(!firstLi) {
					thisNode.style.visibility='hidden';//如果没有下一级就隐藏图片
					ul.style.display='none';//加上这个就是界面美观
					return;
				}
				var parentId = firstLi.getAttribute('parentId');
				if(!parentId)parentId = firstLi.parentId;
				var treeType = firstLi.getAttribute('treeType');
				if(!treeType)treeType = firstLi.treeType;
				if(parentId){
					loadTreeChildNodes(ul.id,parentId,treeType);//外面调用的方法
					//parseSubItems(ul.id,parentId);
					//如果父节点，调用ajax读取数据
					/**
					ajaxObjectArray[ajaxObjectArray.length] = new sack();
					var ajaxIndex = ajaxObjectArray.length-1;
					ajaxObjectArray[ajaxIndex].requestFile = ajaxRequestFile + '?parentId=' + parentId;					
					ajaxObjectArray[ajaxIndex].onCompletion = function() { getNodeDataFromServer(ajaxIndex,ul.id,parentId); };	// Specify function that will be executed after file has been found					
					ajaxObjectArray[ajaxIndex].runAJAX();		// Execute AJAX function
					*/
				}			
			}
			
		}else{//关闭
			thisNode.src = thisNode.src.replace(minusImage,plusImage);
			//增加功能
			if(isFoldopen){//文件夹展开,hyh
				foldImg.src = foldImg.src.replace(folderOpenImage,folderImage);
			}

			parentNode.getElementsByTagName('UL')[0].style.display='none';
			initExpandedNodes = initExpandedNodes.replace(',' + inputId,'');
		}	
		//Set_Cookie('dhtmlgoodies_expandedNodes',initExpandedNodes,500);
		
		return false;
	}
	
	var okToCreateSubNode = true;
	/**
	 * 添加新节点
	 */
	function addNewNode(e){
		if(!okToCreateSubNode)return;
		setTimeout('okToCreateSubNode=true',200);
		contextMenuObj.style.display='none';
		okToCreateSubNode = false;
		source = contextMenuSource;
		while(source.tagName.toLowerCase()!='li')source = source.parentNode;
		//alert(source.innerHTML);
		if(source.getElementsByTagName('A')[0].id){
			//add tree node
			addTreeNode(source.getElementsByTagName('A')[0].id,source.getElementsByTagName('A')[0].innerHTML);
		}
		/*
		if (e.target) source = e.target;
			else if (e.srcElement) source = e.srcElement;
			if (source.nodeType == 3) // defeat Safari bug
				source = source.parentNode; */
		//while(source.tagName.toLowerCase()!='li')source = source.parentNode;
		/**
		var nameOfNewNode = prompt('Name of new node');
		if(!nameOfNewNode)return;
		*/
	}
	
	//no use
	//for add ok
	function addNodeStatic(pId,title){
		var source = document.getElementById(pId);
		source = source.parentNode;//li
		//alert(source.innerHTML);
		uls = source.getElementsByTagName('UL');
		if(uls.length==0){
			var ul = document.createElement('UL');
			ul.id = 'newNode' + Math.round(Math.random()*1000000);
			source.appendChild(ul);
		}else{
			ul = uls[0];
			ul.style.display='block';
		}
		//父节点 "+" 图片，未查看下一级
		var img = source.getElementsByTagName('IMG');
		img[0].style.visibility='visible';

		//子节点内容<li><a href="#">Sweden</a></li>
		var li = document.createElement('LI');
		li.className='dhtmlgoodies_sheet.gif';
		var a = document.createElement('A');
		a.href = '#';
		a.innerHTML = title;
		li.appendChild(a);
		ul.appendChild(li);
		
		parseSubItems(ul.id);
		//alert(source.getElementsByTagName('A')[0].id)
		//saveNewNode(nameOfNewNode,source.getElementsByTagName('A')[0].id);
		//*/
	}
	
	/**
	 * 新增成功重新load父节点
	 */
	function loadNodeByParentId(pId){
		var a = document.getElementById(pId);
		var li = a.parentNode;
		var ul = li.getElementsByTagName('UL')[0];
		//no next tree
		if(!ul){
			var ul = document.createElement('UL');
			ul.id = 'newNode' + Math.round(Math.random()*1000000);//
			li.appendChild(ul);
		}
		DWREngine.setAsync(false);
		loadTreeChildNodes(ul.id,pId);
		DWREngine.setAsync(true);
		var img = li.getElementsByTagName('IMG')[0];
		img.style.visibility='visible';
		
		if(ul.style.display != "block"){//view
			//
			if(img.src.indexOf(plusImage)>=0){
				
			}else{
				img.src = thisNode.src.replace(minusImage,plusImage);
			}
			showHideNode(false,li.id.replace(/[^0-9]/g,''));
		}
	}
	
	/**
	 * 编辑树节点
	 */
	function editNode(e){
		if(!okToCreateSubNode)return;
		setTimeout('okToCreateSubNode=true',200);
		contextMenuObj.style.display='none';
		okToCreateSubNode = false;
		source = contextMenuSource;
		while(source.tagName.toLowerCase()!='li')source = source.parentNode;
		//alert(source.innerHTML);
		if(source.getElementsByTagName('A')[0].id){
			//edit tree node
			editTreeNode(source.getElementsByTagName('A')[0].id,source.parentNode.parentNode.getElementsByTagName('A')[0].innerHTML);
		}
	}
	
	/**
	 * 修改成功修改节点名称
	 */
	function loadNodeById(id,title){
		document.getElementById(id).innerHTML = title;//同时修改树的名称
	}
	
	/**
	 * 删除节点操作
	 */
	function deleteNode(){
		if(!okToCreateSubNode)return;		
		setTimeout('okToCreateSubNode=true',200);		
		contextMenuObj.style.display='none';
		source = contextMenuSource;
		var msg = "你确定删除"+source.innerHTML+"节点";
		if(source.parentNode.getElementsByTagName('LI').length>0){
			msg += "以及它下面所有节点吗？"
		}else{
			msg += "吗？"
		}
		if(!confirm(msg))return;
		okToCreateSubNode = false;
		
		var parentLi = source.parentNode.parentNode.parentNode;
		while(source.tagName.toLowerCase()!='li')source = source.parentNode;
		
		if(source.getElementsByTagName('A')[0].id == "0"){//根节点id写死
			alert("根节点不能删除！");
			return;
		}
		deleteTreeNode(source.getElementsByTagName('A')[0].id);//删除外面调用方法
		//alert(parentLi.innerHTML);
		var lis = source.parentNode.getElementsByTagName('LI');
		source.parentNode.removeChild(source);
		if(lis.length==0){
			parentLi.getElementsByTagName('IMG')[0].style.visibility='hidden';
			parentLi.getElementsByTagName('UL')[0].style.display = '';
		}
	}
	
	/**
	 * 刷新节点
	 */
	function refreshNode(e){
		if(!okToCreateSubNode)return;
		setTimeout('okToCreateSubNode=true',200);
		contextMenuObj.style.display='none';
		okToCreateSubNode = false;
		source = contextMenuSource;
		while(source.tagName.toLowerCase()!='li')source = source.parentNode;
		//alert(source.innerHTML);
		if(source.getElementsByTagName('A')[0].id){
			loadNodeByParentId(source.getElementsByTagName('A')[0].id);
		}
	}
	
	/**
	 * 初始化树
	 */
	function initTree(){
		for(var treeCounter=0;treeCounter<idOfFolderTrees.length;treeCounter++){
			var dhtmlgoodies_tree = document.getElementById(idOfFolderTrees[treeCounter]);
			var menuItems = dhtmlgoodies_tree.getElementsByTagName('LI');	// Get an array of all menu items
			for(var no=0;no<menuItems.length;no++){					
				nodeId++;
				var subItems = menuItems[no].getElementsByTagName('UL');
				var img = document.createElement('IMG');
				img.src = imageFolder + plusImage;
				img.onclick = showHideNode;
				//判断是否有下一级
				if(subItems.length==0){
					img.style.visibility='hidden';
				}else{
					subItems[0].id = 'tree_ul_' + treeUlCounter;
					treeUlCounter++;
				}
				var aTag = menuItems[no].getElementsByTagName('A')[0];
				if(contextMenuActive)aTag.oncontextmenu = showContextMenu;
				//aTag.onclick = showHideNode;
				aTag.ondblclick = showHideNode;//双击事件
				menuItems[no].insertBefore(img,aTag);
				if(!menuItems[no].id)menuItems[no].id = 'dhtmlgoodies_treeNode' + nodeId;
				var folderImg = document.createElement('IMG');
				if(menuItems[no].className){//可以用自定义图片
					folderImg.src = imageFolder + menuItems[no].className;
				}else{
					folderImg.src = imageFolder + folderImage;
				}
				menuItems[no].insertBefore(folderImg,aTag);
			}	
		
		}
		/**hyh
		initExpandedNodes = Get_Cookie('dhtmlgoodies_expandedNodes');
		if(initExpandedNodes){
			var nodes = initExpandedNodes.split(',');
			for(var no=0;no<nodes.length;no++){
				if(nodes[no])showHideNode(false,nodes[no]);
			}
		}
		*/
	}